package rss_POJO;

import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "SONG")
//@Table(name = "SONG", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"TITLE"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Song.findAll", query = "SELECT s FROM Song s"),
    @NamedQuery(name = "Song.findBySongid", query = "SELECT s FROM Song s WHERE s.songid = :songid"),
    @NamedQuery(name = "Song.findByTitle", query = "SELECT s FROM Song s WHERE s.title = :title"),
    @NamedQuery(name = "Song.findByDuration", query = "SELECT s FROM Song s WHERE s.duration = :duration"),
    @NamedQuery(name = "Song.findByTracknr", query = "SELECT s FROM Song s WHERE s.tracknr = :tracknr")})
public class Song implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "SONGID")  // είναι not nullable αλλά και unique ως primary key
        @Basic(optional = false)
        private Integer songid;
    @Column(name = "TITLE", nullable = false, unique = false, length = 100)
        @Basic(optional = false)
        private String title;
    @Column(name = "DURATION", nullable = false, unique = false)
        @Basic(optional = false)
        private Integer duration;
    @Column(name = "TRACKNR", nullable = false, unique = false)
        @Basic(optional = false)
        private Integer tracknr;

    @ManyToOne(optional = false)
        @JoinColumn(name = "ALBUM_ID", referencedColumnName = "ALBUMID", nullable = false, unique = false)
        private Album albumId;
    @ManyToMany(mappedBy = "songCollection")
        private Collection<PlayList> playListCollection;

    /* default constructor */
    public Song() {
    }
    /* και ο πλήρης constructor */
    public Song(String title, Integer duration, Integer tracknr) {
        this.songid = null;
        this.title = title;
        this.duration = duration;
        this.tracknr = tracknr;
    }

    /* getters */
    public Integer getSongid() { return songid; }
    public String getTitle() { return title; }
    public Integer getDuration() { return duration; }
    public Integer getTracknr() { return tracknr; }
    /* getters για foreign keys */
    public Album getAlbumId() { return albumId; }

    /* setters εκτός ίσως από το primary key */
    public void setSongid(Integer songid) { this.songid = songid; }
    public void setTitle(String title) { this.title = title; }
    public void setDuration(Integer duration) { this.duration = duration; }
    public void setTracknr(Integer tracknr) { this.tracknr = tracknr; }
    /* setters για foreign keys */
    public void setAlbumId(Album albumId) { this.albumId = albumId; }


    @XmlTransient
    /* getter και setter για την playListCollection */
    public Collection<PlayList> getPlayListCollection() {
        return playListCollection;
    }
    public void setPlayListCollection(Collection<PlayList> playListCollection) {
        this.playListCollection = playListCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (songid != null ? songid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Song)) {
            return false;
        }
        Song other = (Song) object;
        if ((this.songid == null && other.songid != null) || (this.songid != null && !this.songid.equals(other.songid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.Song[ songid=" + songid + " ]";
    }
    
}